# -*- coding: utf-8 -*-
# @Time    : 2022/7/16 21:20
# @Author  : haichuan
# @Email   : 2263126410@163.com
# @File    : xtbs_xg_bumpage.py
# @Software: PyCharm
from selenium.webdriver.common.by import By
from time import  sleep
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.select import Select
from pages.denglu_page import Deng_BasePage
import unittest


class XgBuMpage(Deng_BasePage):
    '''修改组织架构中的部门'''
    '''进入组织架构'''
    zzjg_xlk=(By.CSS_SELECTOR,'li.dropdown:nth-child(6) > ul:nth-child(2) > li:nth-child(4) > a:nth-child(1)')
    zzjg_jgzz=(By.CSS_SELECTOR,'.page-header > h4:nth-child(1) > small:nth-child(1) > a:nth-child(1)')
                    # '''组织架构-自动化构建部门鼠标悬浮'''
    bumen=(By.XPATH,'/html/body/div[5]/div[2]/form/div[2]/ul/li/ul/li[2]/span')
    '''在编辑部门提示框中'''
    bumen_xg_name=(By.XPATH,'/html/body/div[7]/div[2]/form/div[1]/div/input')
    bumen_xg_sjbm=(By.XPATH,'/html/body/div[7]/div[2]/form/div[2]/div/select')
    bumen_xg_mioashu=(By.XPATH,'/html/body/div[7]/div[2]/form/div[3]/div/textarea')
    bumen_xg_qr=(By.XPATH,'/html/body/div[7]/div[3]/div/button[1]/span')
    shu_xg_name = (By.XPATH ,'/html/body/div[5]/div[2]/form/div[2]/ul/li/ul/li[2]/span/span/a[1]')
    user_Heads = (By.CSS_SELECTOR ,'li.dropdown:nth-child(6) > a:nth-child(1)')
    def __init__ (self,driver):
        self.driver = driver
        self.driver.get( "http://192.168.12.1/crm/" )
        self.action = ActionChains( self.driver )


    def jr_bum(self):
        '''进入组织架构资料'''
        self.driver.find_element(*self.user_Heads).click()
        self.driver.find_element(*self.zzjg_xlk).click()
        sleep(1.5)
        self.driver.find_element(*self.zzjg_jgzz).click()
        '''部门-鼠标悬浮'''
        zdh=self.driver.find_element(*self.bumen )
        self.action.move_to_element(zdh).perform()

    def xg_bum(self):
        zdh_xg = self.driver.find_element(*self.shu_xg_name)
        self.action.move_to_element( zdh_xg ).perform()
        sleep(0.5)
        self.driver.find_element( *self.shu_xg_name ).click()

    def bum_name(self,bum_gx):
        '''在修改部门信息提示框中'''
        sleep( 0.5 )
        self.driver.find_element( *self.bumen_xg_name ).clear()
        self.driver.find_element( *self.bumen_xg_name ).send_keys(bum_gx)

    def xz_sj(self ,sj):
        '''修改上级部门'''
        sleep(0.5)
        bumen_xg_sjbm_xlk = self.driver.find_element(*self.bumen_xg_sjbm)
        select = Select(bumen_xg_sjbm_xlk)
        select.select_by_visible_text(sj)

    def bum_ms(self ,ms):
        sleep(1)
        self.driver.find_element( *self.bumen_xg_mioashu ).clear()
        self.driver.find_element( *self.bumen_xg_mioashu ).send_keys(ms)
        self.driver.find_element( *self.bumen_xg_qr ).click()

    def wzxg_bum(self,bum_gx,sj,ms):
        self.jr_bum()
        self.xg_bum()
        self.bum_name(bum_gx)
        self.xz_sj(sj)
        self.bum_ms(ms)







